
//---------------------------------------------------------------------------
#include "animation/pg1_animation.h"
//---------------------------------------------------------------------------
#include "animation/pg1_timer.h"
//---------------------------------------------------------------------------
using namespace pg1;
//---------------------------------------------------------------------------
Animation::Animation ()
:
m_uiCurrentFrame(0),
m_fCurrentTime(0),
m_fLength(1.0f)
{
	// nothing to do
}
//---------------------------------------------------------------------------
void Animation::addFrame (float fTextureWidth, float fTextureHeight,
				  		  float fFramePosX, float fFramePosY,
					 	  float fFrameWidth, float fFrameHeight
)
{
	Frame kFrame;
	kFrame.u1 = (fFramePosX / fTextureWidth);
	kFrame.v1 = (fFramePosY / fTextureHeight);

	kFrame.u2 = ( (fFramePosX + fFrameWidth) / fTextureWidth);
	kFrame.v2 = (fFramePosY / fTextureHeight);

	kFrame.u3 = (fFramePosX / fTextureWidth);
	kFrame.v3 = ( (fFramePosY + fFrameHeight) / fTextureHeight);

	kFrame.u4 = ( (fFramePosX + fFrameWidth) / fTextureWidth);
	kFrame.v4 = ( (fFramePosY + fFrameHeight) / fTextureHeight);

	m_akFrames.push_back(kFrame);
}
//---------------------------------------------------------------------------
void Animation::update (Timer& rkTimer)
{
	m_fCurrentTime += rkTimer.timeBetweenFrames();
	while(m_fCurrentTime > m_fLength) {
		m_fCurrentTime -= m_fLength;
	}

	m_uiCurrentFrame = static_cast<unsigned int>( (m_fCurrentTime / m_fLength) * m_akFrames.size() );
}
//---------------------------------------------------------------------------
